package xyz.scootaloo.draft.tool

import org.junit.Test
import xyz.scootaloo.alg.tool.TextTable
import xyz.scootaloo.alg.tool.TextTableJavaEdition

/**
 * @author flutterdash@qq.com
 * @since 2021/5/9 22:59
 */
class TestTextTable {

    /**
     * 7200
     * 6359
     */
    @Test
    fun testJavaEdition() {
        val head = Array(100) { idx ->
            "column$idx"
        }
        val body = Array(10000) { _ ->
            Array(100) {
                "xxxxxxxxx"
            }
        }

        val start = System.currentTimeMillis()
        val res = TextTableJavaEdition(head, body).toString()
        val end = System.currentTimeMillis()
        print(end - start)
        println(res)
    }

    @Test
    fun testKotlinEdition() {
        val head = ArrayList<String>()
        for (i in 0 until 100)
            head.add("column$i")
        val body = ArrayList<ArrayList<String>>()
        for (i in 0 until 10000) {
            val new = ArrayList<String>()
            for (j in 0 until 100) {
                new.add("xxxxxxxxx")
            }
            body.add(new)
        }
        body.add(0, head)

        val start = System.currentTimeMillis()
        val res = TextTable.generate(body)
        val end = System.currentTimeMillis()
        println(end - start)
        println(res)
    }

    @Test
    fun simpleTest() {
        val table = ArrayList<List<String>>()
        table.add(arrayListOf("c1", "c2", "c3"))
        table.add(arrayListOf("c1-----", "c2", "c3"))
        table.add(arrayListOf("c1", "c2", ))
        table.add(arrayListOf("c1", "c2", "c3"))
        println(TextTable.generate(table))
    }
}
